By Steve Ewing
January 1, 0001
Can I copy Kyle’s map and post to bsky as a reply?
First the map.
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
options(tigris_use_cache = TRUE)
# Grab the data
us_wfh <- get_acs(
geography = "puma",
variables = "DP03_0024P",
year = 2023,
survey = "acs1",
geometry = TRUE
) ## Getting data from the 2023 1-year ACS
## The 1-year ACS provides data for geographies with populations of 65,000 and greater.
## Warning: • You have not set a Census API key. Users without a key are limited to 500
## queries per day and may experience performance limitations.
## ℹ For best results, get a Census API key at
## http://api.census.gov/data/key_signup.html and then supply the key to the
## `census_api_key()` function to use it throughout your tidycensus session.
## This warning is displayed once per session.
## Using the ACS Data Profile
## Warning: package 'mapgl' was built under R version 4.4.2
# Format the popup
popup_content <- glue::glue(
"<strong>{us_wfh$NAME}</strong><br>",
"% working from home: {us_wfh$estimate}"
)
us_wfh$popup <- popup_content
# Build the interactive map
wfh_map <- mapboxgl(
style = mapbox_style("light"),
center = c(-98.5795, 39.8283),
zoom = 3
) %>%
add_fill_layer(
id = "puma_wfh",
source = us_wfh,
fill_color = interpolate(
column = "estimate",
values = c(1.4, 9.4, 14.9, 22.2, 36.5),
stops = viridisLite::plasma(5),
na_color = "lightgrey"
),
fill_opacity = 0.7,
popup = "popup",
hover_options = list(
fill_color = "cyan",
fill_opacity = 1
)
) %>%
add_legend(
"% working from home by PUMA, 2023 1-year ACS",
values = c("1.4%", "9.4%", "14.9%", "22.2%", "36.5%"),
colors = viridisLite::plasma(5)
)
wfh_map